package com.metadata_system.common.service;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import com.metadata_system.common.db.entity.Config;
import com.metadata_system.common.db.mapper.ConfigMapper;
import com.metadata_system.common.dto.ApiResult;
import com.metadata_system.common.utils.RedisUtil;

import java.util.Map;

@Service
public class CommonConfigService {

    @Autowired(required = false)
    ConfigMapper configMapper;

    @Autowired
    RedisUtil redisUtil;


    /**
     * 获取内容
     * @param key
     * @return
     */
    public String getContentByKey(String key) {
        return this.configMapper.getValueByKey(key);
    }

    /**
     * 设置内容
     * @param key
     * @param content
     */
    public void setContentByKey(String key, String content) {
        Example example = new Example(Config.class);
        example.createCriteria().andEqualTo("myKey", key);
        this.configMapper.updateByExampleSelective(Config.builder()
                .content(content)
                .build(), example);
    }
    

}
